package de.zinulla.moviethek.db;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class MoviesTable {
	// Database table
	public static final String TABLE_MOVIES = "movies";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_MOVIE_NAME = "movie";
	public static final String COLUMN_DIRECTOR = "director";
	public static final String COLUMN_ACTOR = "actor";
	public static final String COLUMN_YEAR = "year";
	public static final String COLUMN_COVER = "cover";
	public static final String COLUMN_RATING = "rating";
	public static final String COLUMN_PLOT = "plot";
	public static final String COLUMN_GENRE = "genre";
	public static final String COLUMN_RUNTIME = "runtime";
	public static final String COLUMN_IMDB_ID = "imdbid";
	public static final String COLUMN_IN_3D = "in3D";
	public static final String COLUMN_MEDIA = "media";
	public static final String COLUMN_COVER_URL = "coverurl";
	public static final String COLUMN_COVER_FILE_NAME = "coverfilename";
	public static final String COLUMN_RENT_NAME = "rentname";
	public static final String COLUMN_RENT_DATE = "rentdate";

	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table " 
												+ TABLE_MOVIES 
												+ "( " 
												+ COLUMN_ID + " integer primary key autoincrement, " 
												+ COLUMN_MOVIE_NAME + " text not null, " 
												+ COLUMN_DIRECTOR + " text not null, " 
												+ COLUMN_ACTOR + " text not null, " 
												+ COLUMN_YEAR + " text not null, " 
												+ COLUMN_COVER + " BLOB not null, " 
												+ COLUMN_RATING + " text not null, " 
												+ COLUMN_PLOT + " text not null, " 
												+ COLUMN_GENRE + " text not null, "
												+ COLUMN_RUNTIME + " text not null, " 
												+ COLUMN_IMDB_ID + " text not null, " 
												+ COLUMN_IN_3D + " text not null, " 
												+ COLUMN_MEDIA + " text not null, " 
												+ COLUMN_COVER_URL + " text not null, " 
												+ COLUMN_COVER_FILE_NAME + " text not null, " 
												+ COLUMN_RENT_NAME + " text not null, " 
												+ COLUMN_RENT_DATE + " text not null " 
												+ ");";
	
	public static void onCreate(SQLiteDatabase database) {
		database.execSQL(DATABASE_CREATE);
	}

	public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(MovieSqlHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_MOVIES);
		onCreate(db);
	}
}
